package com.aier.school.entity.mapper;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Map;

import net.eicp.ghostboy.futil.StringUtil;

import org.springframework.jdbc.core.RowMapper;

import com.aier.school.entity.SchoolInfoDetail;

public class SchoolInfoDetailRowMapper implements RowMapper<SchoolInfoDetail> {
    @SuppressWarnings("unused")
    private int type;

    public SchoolInfoDetailRowMapper() {
    }

    public SchoolInfoDetailRowMapper(int type) {
        this.type = type;
    }

    @Override
    public SchoolInfoDetail mapRow(ResultSet rs, int rowNum) throws SQLException {
        return parseSchoolInfo(new SchoolInfoDetail(), rs);
    }

    public static SchoolInfoDetail parseSchoolInfo(SchoolInfoDetail si, ResultSet rs) throws SQLException {
        return parseSchoolInfo(si, rs, null);
    }

    public static SchoolInfoDetail parseSchoolInfo(SchoolInfoDetail si, ResultSet rs, String su)
        throws SQLException {

        if (StringUtil.isStringNull(su)) {
            su = "";
        } else {
            su += ".";
        }
        try {
            si.setSid(rs.getInt(su+"sid"));
        } catch (SQLException e) {
            si.setSid(null);
        }
        
        try {
            si.setAddress(rs.getString(su+"address"));
        } catch (SQLException e) {
            si.setAddress(null);
        }
        try {
            si.setPhone(rs.getString(su+"phone"));
        } catch (SQLException e) {
            si.setPhone(null);
        }
        try {
            si.setUrl(rs.getString(su+"url"));
        } catch (SQLException e) {
            si.setUrl(null);
        }
        try {
            si.setPostcode(rs.getString(su+"postcode"));
        } catch (SQLException e) {
            si.setPostcode(null);
        }       
        try {
            si.setEmail(rs.getString(su+"email"));
        } catch (SQLException e) {
            si.setEmail(null);
        }       
        try {
            si.setFax(rs.getString(su+"fax"));
        } catch (SQLException e) {
            si.setFax(null);
        }
        return si;
    }

    public static Map<String, Object> getPar(Map<String, Object> par, SchoolInfoDetail si) {
        par.put("sid", si.getSid());
        par.put("address",si.getAddress());
        par.put("phone", si.getPhone());
        par.put("url", si.getUrl());
        par.put("postcode", si.getPostcode());
        par.put("email",si.getEmail());
        par.put("fax",si.getFax());
        return par;
    }

}
